<template>
	<div class="index_page">
		<banner1/>
		<mt-button @click="popMessage">测试弹框提示</mt-button>
		<div class="upload_image">
			<input  name="file" type="file" accept="image/png,image/gif,image/jpeg" @change="update" placeholder="" ref="imgaeFile" style="display:none;" />
			<a href="javascript:;" @click="shangchuan" class="image_upload">点击文件上传</a>
			<img src="../../assets/images/logo.png" ref="thisimgsrc" >
		</div>
		
	</div>
</template>

<script>
	import banner1 from './../public/banner'
	import { MessageBox } from 'mint-ui'
	import { Toast } from 'mint-ui';
	export default ({
		components:{banner1},
		data(){
			return {

			}
		},
		methods:{
			popMessage(){
				// MessageBox.alert('提示内容','提示标题',{confirmButtonText:'操作按钮'})
				var that = this
				MessageBox.confirm('确定登录?').then(action => {
					that.$ajax({
						url:'server/api/user/login',
						method:'post',
						data:{
							username:'admin123',
							password:'admin123'
						}
					})
					.then(function(res){
						if(res.data.code == 200){
							Toast({
							  message: '登录成功',
							  iconClass: 'icon icon-success'
							});
							// that.$ajax({
							// 	url:'server/api/home/list',
							// 	method:'post'
							// })
							// .then(function(res){
							// 	if(res.data.code == 200){
							// 		Toast({
							// 		  message: res.data.data.userAgent
							// 		});
							// 	}
							// })
						}
					})
					
				}).catch(()=>{
					
				});
			},
			update(e){
				var that = this;
      			let file = e.target.files[0];
      			let param = new FormData();
      			param.append('file', file);
      			let config = {
        			headers: {'Content-Type': 'multipart/form-data'}
      			}
      			this.$ajax.post('server/api/upload/file/generalFile', param, config)
      			.then(function(res){
      				if(res.data.code == 200){
      					that.$refs.thisimgsrc.src='https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523608026457&di=eb9e9f65180d5f4271ce828d1c1dcdb4&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimage%2Fc0%253Dpixel_huitu%252C0%252C0%252C294%252C40%2Fsign%3Db360ab28790e0cf3b4fa46bb633e9773%2Fe850352ac65c10387071c8f8b9119313b07e89f8.jpg'
      				}
      			})
			},
			shangchuan(){

				this.$refs.imgaeFile.click();
			}
		}
	})
</script>

<style lang='less'>
	.index_page .mint-button--normal{
		font-size: 0.373333rem !important;padding: 0 0.32rem !important;margin: 0.266667rem  auto !important;display: block !important;
	}
	.upload_image{
		.image_upload{
			display:block;width: 5rem;height: 1.066667rem;line-height: 1.066667rem;text-align: center;background:#ccc;color: red;margin:0 auto;
			font-size:0.373333rem;
		}
		img{
			width:8rem;height: 8rem;display:block;margin:0 auto; border:none; 
		}
	}
</style>